using Avalonia;
using Avalonia.Controls;
using Avalonia.Interactivity;
using Avalonia.Layout;
using Avalonia.Markup.Xaml;

namespace SocketTool.Views.DialogWindows
{
    public partial class AddNewSocketWindow : Window
    {
        public AddNewSocketWindow()
        {
            InitializeComponent();
#if DEBUG
            this.AttachDevTools();
#endif
        }

        private void InitializeComponent()
        {
            AvaloniaXamlLoader.Load(this);
        }

        /// <summary>
        /// 添加协议头
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void AddHead_OnClick(object? sender, RoutedEventArgs e)
        {
            var headPanel = this.FindControl<StackPanel>("ProtocolHeadPanel");
            headPanel.Children.Insert(0, this.CreateProtocolTextBox());
        }
        
        /// <summary>
        /// 添加协议尾
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void AddTail_OnClick(object? sender, RoutedEventArgs e)
        {
            var tailPanel = this.FindControl<StackPanel>("ProtocolTailPanel");
            tailPanel.Children.Add(this.CreateProtocolTextBox());

            var scrollView = this.FindControl<ScrollViewer>("ProtocolEditScroll");
        }

        /// <summary>
        /// 生成自定义协议编辑框
        /// </summary>
        /// <returns></returns>
        private TextBox CreateProtocolTextBox()
        {
            TextBox result = new TextBox();
            result.Text = "00";
            result.Width = 45;
            result.Padding = new Thickness(0);
            result.HorizontalContentAlignment = HorizontalAlignment.Center;
            result.VerticalContentAlignment = VerticalAlignment.Center;
            result.MinWidth = 0;
            return result;
        }
    }
}